<?php

namespace common\models;

use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use yii\db\ActiveRecord;
use yii\db\Expression;
use common\behaviors\ActiveRecordHistoryBehavior;
class Basic extends ActiveRecord
{

    /**
     * @inheritdoc
     * @return array mixed
     */
    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::class,
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at',
                'value' => new Expression('NOW()'),
            ],
            BlameableBehavior::class,
            ActiveRecordHistoryBehavior::class,
        ];
    }


    /**
     * @return bool
     */
    public function beforeValidate(): bool
    {
        foreach ($this->attributes as $k=>$v){
            $this->$k= trim($v);
        }
        return parent::beforeValidate();
    }


}
